import { Injector, Univer } from '@univerjs/core';
import { FUniver } from '@univerjs/facade';

import { JnpfFacadeSheetsEchart } from '../facade/f-sheet-echart';
import { JnpfSheetsEchartService } from '../services/sheet-echart.service';

import { JnpfFacadeSheetsCell } from '../facade/f-sheet-cell';
import { JnpfSheetsCellService } from '../services/sheet-cell.service';

import { JnpfFacadeSheetsPrint } from '../facade/f-sheet-print';
import { JnpfSheetsPrintService } from '../services/sheet-print.service';

import { JnpfFacadeSheets } from '../facade/f-sheet';

export class JnpfFUniver extends FUniver {
  static newAPI(wrapped: Univer | Injector): JnpfFUniver {
    const injector = wrapped instanceof Univer ? wrapped.__getInjector() : wrapped;
    return injector.createInstance(JnpfFUniver);
  }

  getSheets(): JnpfFacadeSheets | null {
    return this._injector.createInstance(JnpfFacadeSheets);
  }

  getSheetsCell(): JnpfFacadeSheetsCell | null {
    const jnpfSheetsCellService = this._injector.get(JnpfSheetsCellService);

    if (!jnpfSheetsCellService) {
      return null;
    }

    return this._injector.createInstance(JnpfFacadeSheetsCell, jnpfSheetsCellService);
  }

  getSheetsEchart(): JnpfFacadeSheetsEchart | null {
    const jnpfSheetsEchartService = this._injector.get(JnpfSheetsEchartService);

    if (!jnpfSheetsEchartService) {
      return null;
    }

    return this._injector.createInstance(JnpfFacadeSheetsEchart, jnpfSheetsEchartService);
  }

  getSheetsPrint(): JnpfFacadeSheetsPrint | null {
    const jnpfSheetsPrintService = this._injector.get(JnpfSheetsPrintService);

    if (!jnpfSheetsPrintService) {
      return null;
    }

    return this._injector.createInstance(JnpfFacadeSheetsPrint, jnpfSheetsPrintService);
  }
}
